package com.gqb.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.gqb.load.ControllerLoad;
import com.gqb.spring.bean.BeanA;
import com.gqb.spring.framework.FacadeBeanFactory;

public class InitContextListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		ServletContext servletContext=sce.getServletContext();
		String path=servletContext.getContextPath();
		String pathXmlString=servletContext.getRealPath("/WEB-INF/classes/beans.xml");
		try {
			FacadeBeanFactory facadeBeanFactory=new FacadeBeanFactory(pathXmlString);
			/*BeanA beanA=(BeanA) facadeBeanFactory.getBean("beanA");
			System.out.println(beanA.getTitle());
			System.out.println(beanA.getBeanB().getTitle());*/
			ControllerLoad.load(facadeBeanFactory.getBeans().getScans());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// TODO Auto-generated method stub
		
	}

}
